#include<vector>
#include<string>
using namespace std;

bool checkPartitioning(string s) {
    int n = s.size();
    vector<vector<bool>> dp(n, vector<bool>(n));
    int ret = 0;
    // dp[i][j] = dp[i+1][j-1]
    for (int i = n - 1; i >= 0; i--)
    {
        for (int j = i; j < n; j++)
        {
            if (s[i] == s[j])
            {
                if (i == j) dp[i][j] = true;
                else if (i + 1 == j) dp[i][j] = true;
                else dp[i][j] = dp[i + 1][j - 1];
            }
        }
    }
    for (int i = 1; i < n - 1; i++)
    {
        for (int j = i; j < n - 1; j++)
        {
            if (dp[i][j])
            {
                if (dp[0][i - 1] && dp[j + 1][n - 1]) return true;
            }
        }
    }
    return false;
}

int minCut(string s) {
    int n = s.size();
    vector<vector<bool>> dp(n, vector<bool>(n));
    int ret = 0;
    vector<int> res(n, INT_MAX);
    // dp[i][j] = dp[i+1][j-1]
    for (int i = n - 1; i >= 0; i--) {
        for (int j = i; j < n; j++) {
            if (s[i] == s[j]) {
                if (i == j)
                    dp[i][j] = true;
                else if (i + 1 == j)
                    dp[i][j] = true;
                else
                    dp[i][j] = dp[i + 1][j - 1];
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        if (dp[0][i]) res[i] = 0;
        else
        {
            for (int j = 1; j <= i; j++)
            {
                if (dp[j][i]) res[i] = min(res[j - 1] + 1, res[i]);
            }
        }
    }
    return res[n - 1];
}

int main()
{
    checkPartitioning("afdsafvas");
    minCut("sfagrhsa");

	return 0;
}